package com.shen.shennetwork

import android.Manifest
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.net.wifi.WifiInfo

import android.net.wifi.WifiManager

import androidx.core.app.ActivityCompat

import android.content.pm.PackageManager

import androidx.core.content.ContextCompat

import android.os.Build




class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        WifiUtil.ins.init(this)

        //安卓9.0以上版本进行定位权限获取
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            if (ContextCompat.checkSelfPermission(this@MainActivity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { //未开启定位权限
                // 申请定位权限,200是标识码
                ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 200)
            }
        }

        findViewById<Button>(R.id.btn_check).setOnClickListener {
            checkNetwork()
        }


        findViewById<Button>(R.id.btn_change).setOnClickListener {
            WifiUtil.ins.changeToWifi(this, "辉的热点", "")
        }


        findViewById<Button>(R.id.btn_change_ziroom2905_5G).setOnClickListener {
            WifiUtil.ins.changeToWifi(this, "ziroom2905_5G", "")
        }
    }


    private fun checkNetwork(){
        findViewById<TextView>(R.id.tv_content).text = "isMobileConnected:${NetworkUtils.isMobileConnected(this)}\n" +
                "isWifiConnected:${NetworkUtils.isWifiConnected(this)}\n" +
                "isNetworkConnected:${NetworkUtils.isNetworkConnected(this)}\n\n\n" +
                "WifiInfo-------------------------\n:${NetworkUtils.getCurrWifiInfo(this)}"
    }

}